package com.offcn.order.controller;

import com.offcn.common.response.AppResponse;
import com.offcn.order.pojo.TOrder;
import com.offcn.order.service.OrderService;
import com.offcn.order.vo.req.OrderInfoSubmitVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags="保存订单")
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @ApiOperation("添加订单")
    @PostMapping("/createOrder")
    public AppResponse<TOrder> createOrder(@RequestBody OrderInfoSubmitVo vo){
        TOrder tOrder = null;
        try {
            System.out.println(vo);
            tOrder = orderService.saveOrder(vo);
            AppResponse<TOrder> ok = AppResponse.ok(tOrder);
            return ok;
        } catch (Exception e) {
            e.printStackTrace();
            AppResponse<TOrder> fail = AppResponse.fail(null);
            fail.setMsg(e.getMessage());
            return fail;
        }

    }



}
